<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>新增名片</title>
    {include file="common/linkcss" /}
</head>


<body>

    <div class="container-fluid">
        <div class="row">

            {include file="common/sidebar" /}

            <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">

                <div class="card border-primary  ">
                    <form action="{:url('add')}" method="POST" enctype="multipart/form-data">
                        <div class="card-header">
                            <h1 class="page-header">
                                新增名片
                            </h1>
                        </div>
                        <div class="card-body">
                            <div class="form-group">
                                <label class="col-form-label col-form-label-lg">头像【尺寸418*418】</label>
                                <input type="file" class="form-control-file" id="upload" accept="image/*">
                                <div style="padding-top:20px;">
                                    <img src="" alt="" id="uploadres" width="200" height="200">
                                </div>
                                <input type="hidden" name="image" id="image" value="">
                            </div>
                            <div class="form-group">
                                <label class="col-form-label col-form-label-lg">名称</label>
                                <input class="form-control form-control-lg" name="name" type="text" placeholder="" required autofocus>
                            </div>
                            <div class="form-group">
                                <label class="col-form-label col-form-label-lg">英文名称</label>
                                <input class="form-control form-control-lg" name="name_en" type="text" placeholder="">
                            </div>
                            {if session('adminLevel')}
                            <div class="form-group">
                                <label class="col-form-label col-form-label-lg">所属分公司【<a href="{:url('company/add')}">录入分公司</a>】</label>
                                <select class="form-control  form-control-lg" name="company_id">
                                    <option value="0">请选择分公司</option>
                                    {volist name="company" id="vo"}
                                    <option value="{$vo.id}">{$vo.title}</option>
                                    {/volist}
                                </select>
                            </div>
                            {/if}

                            <div class="form-group">
                                <label class="col-form-label col-form-label-lg">所属部门【<a href="{:url('depart/add')}">录入部门</a>】</label>
                                <select class="form-control  form-control-lg" onchange="selectDepart(this.value)" name="did">
                                    <option value="0">请选择部门</option>
                                    {volist name="depart" id="vo"}
                                    <option value="{$vo.id}">{$vo.name}</option>
                                    {/volist}
                                </select>
                            </div>

                            <div class="form-group" id="job_box" style="display:none">
                                <label class="col-form-label col-form-label-lg">职位【<a href="{:url('job/add')}">录入职位</a>】</label>
                                <select class="form-control  form-control-lg" id="job_select" name="job_id">
                                    <option value="0">请选择职位</option>
                                </select>
                            </div>

                            <script id="jobScript" type="text/html">
                                <% for (var i = 0; i < data.length; i ++) { %>
                                    <option value="<%= data[i].id%>"><%= data[i].name %> / <%= data[i].des %></option>
                                <% } %>
                            </script>

                            <div class="form-group">
                                <label class="col-form-label col-form-label-lg">手机号</label>
                                <input class="form-control form-control-lg" name="phone" type="text" placeholder="" required>
                            </div>
                            <div class="form-group">
                                <label class="col-form-label col-form-label-lg">分机号</label>
                                <input class="form-control form-control-lg" name="extension" type="text" placeholder="">
                            </div>
                            <div class="form-group">
                                <label class="col-form-label col-form-label-lg">邮箱</label>
                                <input class="form-control form-control-lg" name="email" type="text" placeholder="" required>
                            </div>
                            <div class="form-group">
                                <label class="col-form-label col-form-label-lg">微信号</label>
                                <input class="form-control form-control-lg" name="wechat" type="text" placeholder="">
                            </div>

                            <div class="form-group">
                                <label class="col-form-label col-form-label-lg">员工职位类型</label>
                                <div class="form-group">
                                    <div class="custom-control custom-radio">
                                        <input type="radio" id="is_foreign[0]" class="custom-control-input" name="is_foreign" value="0">
                                        <label class="custom-control-label" for="is_foreign[0]">外援</label>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="custom-control custom-radio">
                                        <input type="radio" id="is_foreign[1]" class="custom-control-input" checked name="is_foreign" value="1">
                                        <label class="custom-control-label" for="is_foreign[1]">员工</label>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="card-footer">
                            <button type="submit" class="btn btn-primary btn-lg">确认提交</button>
                        </div>
                    </form>
                </div>


            </div>
            <!-- main end -->


        </div>
    </div>
    <!-- container end -->

</body>
<script>
    $('#upload').change(function () {
        var formData = new FormData();
        formData.append("file", $(this).get(0).files[0]);
        $.ajax({
            url: "{:url('index/upload')}",
            type: 'POST',
            data: formData,
            cache: false,
            contentType: false, //不可缺
            processData: false, //不可缺
            success: function (data) {
                $('#uploadres').attr('src', '__UPLOADS__/' + data);
                $('#image').val(data);
            }
        });
    })

    function selectDepart($val) {
        if ($val > 0) {
            $.get("{:url('job/ajaxlst')}", {
                did: $val,
            }, function (res) {
                var html = template('jobScript', res);
                $('#job_select').html(html);
                $('#job_box').show();
            })
        } else {
            $('#job_box').hide();
            $('#job_select').html(' ');
        }
    }
</script>

</html>